package com.sky.controller.admin;

import com.sky.constant.ShopConstant;
import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

/**
 * @Description TODO
 * @Author itheima
 * @Date 2023-07-15 11:36
 */
@Api(tags = "店铺营业状态设置接口")
@Slf4j
@RestController("AdminShopControcller")
@RequestMapping("/admin/shop")
public class ShopController {
    @Autowired
    private RedisTemplate redisTemplate;

    /**
     * 设置店铺状态
     * @param status
     * @return
     */
    @PutMapping("/{status}")
    @ApiOperation("店铺状态设置")
    public Result setshopstatus(@PathVariable Integer status) {
        log.info("店铺状态设置:设置店铺状态为"+(status==1?ShopConstant.SHOP_STATUS_ONE:ShopConstant.SHOP_STATUS_ZERO));
        redisTemplate.opsForValue().set("SHOP_STATUS",status);
        return Result.success();
    }

    /**
     * 查询店铺状态
     * @return
     */
    @GetMapping("/status")
    @ApiOperation("获取店铺状态")
    public Result<Integer> getshopstatus( ) {
        Integer shopStatus = (Integer) redisTemplate.opsForValue().get("SHOP_STATUS");
        if (shopStatus==null){
            shopStatus=0;
        }
        return Result.success(shopStatus);
    }
    }
